package com.rfs.design.templatemethod;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("templatemethod")
public class TemplateMethodController {
    private static Map<Long, Integer> items = new HashMap<>();

    static {
        items.put(1L, 2);
        items.put(2L, 4);
    }

    @Autowired
    private CartFactory cartFactory;
    @GetMapping("right")
    public Cart right(@RequestParam("userId") int userId) {
        CartTypeEnum cartTypeEnum = Db.getUserCategory(userId);
        //AbstractCart cart = (AbstractCart) applicationContext.getBean(userCategory + "UserCart");
        AbstractCart cart = cartFactory.getCart(cartTypeEnum);
        return cart.process(userId, items);
    }
}
